﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using School.Entities;

namespace School.Pages.Admission.Reports
{
    public partial class ShowClassCources : System.Web.UI.Page
    {
        SchoolEntities db = new SchoolEntities();
        string[] days = { "السبت", "الأحد", "الأثنين", "الثلاثاء", "الأربعاء", "الخميس" };
        string[] courses = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };

        protected void Page_Load(object sender, EventArgs e)
        {
            int cls =0;
            int yearId = 0;
            lblYear.Text = " الجدول الدراسى للفصل ( ";
            int studentId = Convert.ToInt32(Session["studentId"]);
            var classStudents = db.TE_Class_Student.SingleOrDefault(y => y.Student_Id == studentId);
            if (classStudents != null)
            {
                cls = Convert.ToInt32(classStudents.Class_Id);
                yearId = Convert.ToInt32(classStudents.EductionalYear_Id);
            }

            var classes = db.ORG_Class.SingleOrDefault(y => y.Id == cls);
            var eduYear = db.ORG_EductionalYear.SingleOrDefault(y => y.Id == yearId);

            if (classes != null && eduYear != null)
            {
                lblYear.Text += classes.Name;
                lblYear.Text += " ) للعام الدراسى ";
                lblYear.Text += eduYear.name;
            }

            string html = "<table border='1' cellpadding='0' cellspacing='0' >";
            html += "  <tr style='background-color:Gray' >";
            html += "        <th >اليوم / الحصة</th>";
            foreach (var x in courses)
            {
                html += "       <th>" + x + "</th>";
            }
            html += "  </tr>";
            for (int i = 0; i < days.Count(); i++)
            {
                html += "    <tr>";
                html += "        <th style='background-color:Gray;width:100px;'>" + days[i] + "</th>";
                foreach (var x in courses)
                {
                    var value = "";
                    var subname = "";

                    try
                    {
                        var sess = int.Parse(x);
                        var d = db.TE_Class_Course.Single(y => y.Class == cls && y.Day == i && y.Session == sess);
                        value = "value='" + d.Te_Teacher_Subject.Id + "'";
                        subname = d.Te_Teacher_Subject.TE_Subject.Subject_Name;
                    }
                    catch (Exception ex)
                    {
                        var exx = ex;
                    }

                    html += "       <td style='width:100px'>";
                    html += "<input type='hidden' name='c_" + x + "_" + i + "' " + value + "/>";
                    html += "  <span class='course'>" + subname + "</span> ";
                    html += "       </td>";
                }
                html += "    </tr>";
            }
            html += "</table>";

            CoursesContainer.InnerHtml = html;
        }
    }
}